<!-- 年龄模块 -->
<template>
  <div class="age">
    <div class="container">
      <!-- 标题 -->
      <div class="tit">年龄比例</div>
      <!-- 饼状图 -->
      <div class="echarts" ref="charts"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
/* 引入 echarts */
import * as echarts from 'echarts'
import { onMounted, reactive, ref } from 'vue'
/* echarts 的DOM实例 */
const charts = ref<any>()
/* echarts需要渲染的数据 */
const ageEcharts = reactive({
  tooltip: {
    trigger: 'item',
  },
  /* 筛选 */
  legend: {
    orient: 'vertical',
    right: '10px',
    top: '20px',
    textStyle: {
      color: '#fff',
    },
  },
  series: [
    {
      name: '旅游人数',
      type: 'pie',
      radius: ['55%', '30%'],
      center: ['50%', '50%'],
      avoidLabelOverlap: false,
      itemStyle: {
        /* 边框 */
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2,
      },
      /* 鼠标放上去的提示信息位置 */
      label: {
        show: false,
        position: 'center',
      },
      emphasis: {
        /* 鼠标放上去的字体 */
        label: {
          show: true,
          fontSize: 30,
          fontWeight: 'bold',
        },
      },
      labelLine: {
        show: false,
      },
      data: [
        { value: 1048, name: '学生' },
        { value: 735, name: '20岁' },
        { value: 580, name: '50岁以上' },
        { value: 484, name: '60岁以上' },
        { value: 300, name: '70岁' },
      ],
    },
  ],
  /* 布局 */
  grid: {
    left: 0,
  },
})
/* 初始化 Echarts */
onMounted(() => {
  /* 获取Echarts 实例对象 */
  const myEcharts = echarts.init(charts.value)
  /* 渲染数据 */
  myEcharts.setOption(ageEcharts)
})
</script>

<style lang="scss" scoped>
.age {
  width: 100%;
  height: 100%;
  padding-top: 10px;
  .container {
    position: relative;
    width: 100%;
    height: 100%;
    background: url('../../images/dataScreen-main-lb.png') no-repeat;
    background-size: 100% 100%;
    /* 标题 */
    .tit {
      position: absolute;
      top: 10px;
      left: 0;
      width: 100%;
      height: 40px;
      color: #ffff;
      font-size: 22px;
      background: url('../../images/dataScreen-title.png') no-repeat left bottom;
    }
    /* 饼状图 */
    .echarts {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
